package swingExtensions.dialog;

import io.github.jonestimd.swing.ButtonBarFactory;
import io.github.jonestimd.swing.dialog.Dialogs;
import io.github.jonestimd.swing.dialog.ExceptionDialog;
import swingExtensions.demo.FrameDemo;

import javax.swing.*;

public class ExceptionDialogDemo {

    protected JPanel createContentPanel() {
        JButton showException = new JButton("showException", null);
        showException.addActionListener(e -> {
            try {
                int value = 2 / 0;
            } catch (Exception ex) {
                ExceptionDialog exceptionDialog = new ExceptionDialog(null, "异常信息", ex);
                exceptionDialog.setVisible(true);
            }
        });
        ButtonBarFactory buttonBarFactory = new ButtonBarFactory();
        buttonBarFactory.add(showException).border(5, 5);
        return (JPanel) buttonBarFactory.get();
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            ExceptionDialogDemo demo = new ExceptionDialogDemo();
            FrameDemo frameDemo = new FrameDemo(ExceptionDialogDemo.class.toString());
            frameDemo.setContentPane(demo.createContentPanel());
            frameDemo.setVisible(true);
        });
    }
}
